package work.timejay.shop.controller;



import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import work.timejay.shop.entity.UserItem;
import work.timejay.shop.service.UserItemService;

import javax.websocket.server.PathParam;
import java.nio.charset.StandardCharsets;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wwj
 * @since 2021-12-18
 */
@RestController
@RequestMapping("/userItem")
public class UserItemController {
    @Autowired
    private UserItemService userItemService;
    /**
     * 用户添加商品
     * @param itemName
     * @param userId
     * @return
     */
    @GetMapping(value = "/addItem")
    //@GlobalTransactional(name = "seata-server", rollbackFor = Exception.class)
    String addItem(@RequestParam("name") String itemName, @RequestParam("userId") Long userId){
        //addItem
        int addResult = userItemService.getBaseMapper().insert(new UserItem(itemName, userId));
        System.out.println("即将执行分布式事务");
        //int i = 1/0;
        if(0 >= addResult){
            return "error";
        }
        return "success";
    }
}

